<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { numberApi } from '@/api/controller';
  import { ToastSuccess, Toastloading } from '@/utils/public';
  import serachUserid from '@/components/serachUserid/index.vue';
  import Pagination from "@/components/Pagination/index.vue";
  import blackForm from './components/blackForm.vue';
  const blackFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page:1,
    limit:20,
    user_id:'',
    status:''
  })
  const stateList = [
    {key:0,label:'全部'},
    {key:1,label:'黑名单记录'},
    {key:2,label:'被解封的记录'},
  ]
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      page:1,
      limit:20,
      user_id:'',
      status:''
    })
    getList()
  }
  const handleRelieve = (row:any = {},formType=1)=>{
    blackFormRef.value.openDialog({...row,formType})
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await numberApi.blackList(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">状态：</div>
          <el-select v-model="listQuery.status" clearable placeholder="请选择状态">
            <el-option
              v-for="item in stateList"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            />
          </el-select>
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
          <el-button type="danger" @click="handleRelieve({},1)">封禁</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="180" prop="created_at" label="封禁时间" />
      <el-table-column width="100" prop="user_id" label="用户ID" />
      <el-table-column width="100" prop="uuid" label="用户UUID" />
      <el-table-column min-width="180" show-overflow-tooltip prop="nickname" label="用户昵称" />
      <el-table-column width="180" show-overflow-tooltip prop="union_name" label="充值金额(元)">
        <template #default="scope">
          {{ (scope.row.rechargePrice / 100).toFixed(2) }}
        </template>
      </el-table-column>
      <el-table-column min-width="180" show-overflow-tooltip prop="desc" label="封禁原因" />
      <el-table-column min-width="180" show-overflow-tooltip prop="reason" label="解封原因" />
      <el-table-column width="100" prop="status" label="状态">
        <template #default="scope">
          {{ ['已解封','黑名单'][scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column width="120" fixed="right" label="操作">
        <template #default="scope">
          <el-button v-if="scope.row.status == 1" type="success" @click="handleRelieve(scope.row,2)" >解封</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
      <blackForm ref="blackFormRef" @updateList="getList" />
  </div>
</template>